package com.lixianbiao.validation;

import com.lixianbiao.validation.compoent.Handler;
import com.lixianbiao.validation.compoent.Message;
import com.lixianbiao.validation.handler.ProcessHandler;
import com.lixianbiao.validation.handler.UsernameExitsHandler;

public class Main {
    public static void main(String[] args) throws IllegalAccessException {
        // 责任链工厂
        Handler.Builder<User> builder = new Handler.Builder<>();
        // 添加责任链节点, TODO 泛型安全警告，可以分成2次检测
        Handler<User> userHandler = builder.addHandler(new ProcessHandler()).
                addHandler(new UsernameExitsHandler()).build();
        // 响应消息
        Message message = new Message();
        // 检测参数
        User user = new User("admin123","Aa12345678@","+8613912345678",120);
        // 开始检测
        userHandler.doHandler(user,message);
        if(!message.result){
            System.out.println("message.toString() = " + message);
        }else {
            System.out.println("执行后面逻辑");
        }

    }
}